<template>
  <vol-box :lazy="true" v-model="model" title="选择运维合同" :height="400" :width="1200" :padding="5"
    :onModelClose="onModelClose">
    <div>
      <operationsContract ref="operationsContract"></operationsContract>
    </div>
    <template #footer>
      <div>
        <el-button type="primary" size="small" @click="onSelect">确认</el-button>
      </div>
    </template>
  </vol-box>
</template>
<script>
import VolBox from "@/components/basic/VolBox.vue";
import operationsContract from "@/views/operationsinfo/operations_contract/q_operations_contract.vue";
//这里使用的vue2语法，也可以写成vue3语法
export default {
  components: {
    "vol-box": VolBox,
    operationsContract,
  },
  data() {
    return {
      model: false,
    };
  },
  methods: {
    async onModelClose() {
      this.$refs.operationsContract.searchFormFields.Voucher_sub = null;
      this.$refs.operationsContract.searchFormFields.Client_name = null;
      this.$refs.operationsContract.searchFormFields.AuditStatus = "1";
      this.$refs.operationsContract.searchFormFields.state = "0";
      // this.$refs.operationsContract.searchFormFields.Client_man = null;
      // this.$refs.operationsContract.searchFormFields.Total_price = null;
      this.$refs.operationsContract.searchFormFields.StartTime = null;
      // this.$refs.operationsContract.searchFormFields.Goods_num = null;
      this.$refs.operationsContract.searchFormFields.EndTime =null;
      this.$refs.operationsContract.$refs.grid.$refs.table.reset()
      this.$store.commit("setTabelText", true)

    },
    open(off = true) {
      this.model = true;
      let setIntervalTiem = setInterval(() => {
        if (this.$refs.operationsContract && off) {
          clearInterval(setIntervalTiem);
          // this.$refs.operationsContract.searchFormFields.Delivery_time = [
          //   this.base.getDate(),
          //   "",
          // ];
          // this.$refs.operationsContract.searchFormFields.AuditStatus = "1";
          this.$refs.operationsContract.$refs.grid.search();
        }
      }, 100);
    },

    onSelect() {
      let rowObj = this.$refs.operationsContract.$refs.grid.getSelectRows();
      if (!rowObj.length || rowObj.length > 1) {
        this.base.ElMessageFn("请选择一条数据");
        return (this.model = true);
      }
      let AuditStatusSome = rowObj.some((item) => item.AuditStatus != 1);
      if (AuditStatusSome) {
        this.base.ElMessageFn("请选择审核通过的合同", "warning")
        return;
      }
      let stateSome = rowObj.some((item) => item.state == "1");
      if (stateSome) {
        this.base.ElMessageFn("过期合同", "warning")
        // return;
      }
      this.$emit("parentCall", ($parent) => {
        if (this.$route.path == "/q_operations" || this.$route.path == "/q_fittings_delivery") {
          $parent.editFormFields.Operations_contract =
            rowObj[0].Operations_contract;
          $parent.editFormFields.Operations_contract_sub = rowObj[0].Voucher_sub;
          $parent.editFormFields.Site = rowObj[0].Site;
          $parent.editFormFields.Client_name = rowObj[0].Client_name;
        }
        if(this.$route.path == "/q_operations_site"){
          // console.log(" this.$refs.operationsContract.$refs.grid", this.$refs.operationsContract.$refs.grid.dicKeys)
          
          if(this.$refs.operationsContract.$refs.grid.dicKeys.length){
            const arr = this.$refs.operationsContract.$refs.grid.dicKeys.filter(item=>item.dicNo.includes("客户"))
            if(arr.length){
              const arr2 =  arr[0].data.filter(item=>item.key==rowObj[0].Client_name)
              if(arr2.length){
                const  kehu= arr2[0].value
                $parent.editFormFields.Operations_contract =
                  rowObj[0].Operations_contract;
                $parent.editFormFields.Operations_contract_sub = rowObj[0].Voucher_sub;
                $parent.editFormFields.Site = rowObj[0].Site;
                $parent.editFormFields.Client_name = kehu;
              }
            }
          }
          // $parent.editFormFields.Operations_contract =
          //   rowObj[0].Operations_contract;
          // $parent.editFormFields.Operations_contract_sub = rowObj[0].Voucher_sub;
          // $parent.editFormFields.Site = rowObj[0].Site;
          // // $parent.editFormFields.Client_name = rowObj[0].Client_name;
          // $parent.editFormFields.Client_name = kehu;
        }
      });
      this.onModelClose();
      return (this.model = false);
    },
  },
};
</script>